/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author Emergenza
 */
@Stateless
public class Registration {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    private String name;
    private String surname;
    private String email;
    private String password;
    private String password2;

    public Registration() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getEmain() {
        return email;
    }

    public void setEmain(String emain) {
        this.email = emain;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Registration(String name, String surname, String email, String password, String password2) {
        this.name = name;
        this.surname = surname;
        this.email = email;
        this.password = password;
        this.password2 = password2; 
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword2() {
        return password2;
    }

    public void setPassword2(String password2) {
        this.password2 = password2;
    }
    
    private void check() throws Exception{
        if(name.length()<= 0){
            throw new Exception("Unacceptable name");
        }
        if(surname.length()<= 0){
            throw new Exception("Unacceptable surname");
        }
        if(password.length()<= 0){
            throw new Exception("Unacceptable password");
        }
        if(password2.length()<= 0){
            throw new Exception("Unacceptable password");
        }
        if(password != password2){
            throw new Exception("Unacceptable password");
        }
        if(email.length()<= 0){
            throw new Exception("Unacceptable email address");
        }else{
            char c;
            boolean at = false;
            boolean dot = false;
            for(int i= 0; i < email.length(); i++){
                c = email.charAt(i);
                if(c == '@'){
                    at = true;
                }
                if(c == '.' && at){
                    dot = true;
                }
            }
            if(!at || !dot){
                throw new Exception("Unacceptable email address");
            }
        }
    }
    public void save(){
        try {
            check();
        } catch (Exception ex) {
            Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //salvare dati in database
        
        //salvare dati in database
    }
}
